import { recognizeQRCode } from './qrcode-recognizer.js';
import path from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

/**
 * 测试二维码识别功能
 */
async function testQRCodeRecognition() {
  console.log('🧪 开始测试二维码识别功能...\n');

  // 这里需要一个测试图片路径
  const testImagePath = path.join(__dirname, '../test-images/qrcode-sample.png');

  try {
    console.log(`📸 测试图片: ${testImagePath}`);
    const result = await recognizeQRCode(testImagePath);

    if (result.success) {
      console.log('✅ 识别成功!');
      console.log(`📊 识别到 ${result.count} 个二维码:`);
      result.data.forEach((qr, index) => {
        console.log(`\n二维码 #${index + 1}:`);
        console.log(`  内容: ${qr.text}`);
        console.log(`  位置:`, qr.location);
      });
    } else {
      console.log('❌ 识别失败:', result.error);
    }
  } catch (error) {
    console.error('❌ 测试出错:', error.message);
  }
}

// 运行测试
testQRCodeRecognition();

